package springtest.nettySocketio.listener;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.DataListener;

import springtest.nettySocketio.User;

/**
 * @author chenzhiqiang
 * @date 2018-07-03 17:04:09
 */

@Service
public class SendDateListener implements DataListener<User> {

    @Autowired
    private SocketIOServer socketIOServer;

    @Override
    public void onData(SocketIOClient client, User data, AckRequest ackSender) throws Exception {
        Collection<SocketIOClient> allClients = socketIOServer.getAllClients();
        // System.out.println(data);
        // SocketIONamespace namespace = client.getNamespace();
        // Collection<SocketIOClient> allClients = namespace.getAllClients();
        User user = new User();
        user.setId("1");
        user.setName("tset");
        for (SocketIOClient clients : allClients) {
            clients.sendEvent("hello", user);
        }
    }

}
